#include "MainWindow.h"
#include "ui_MainWindow.h"

MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow)
{
	ui->setupUi(this);

	_client = new ClientHandle(this);

	connect(ui->btnConnect,SIGNAL(clicked()),SLOT(onBtnConnect()));
	connect(ui->btnDisconnect,SIGNAL(clicked()),SLOT(onBtnDisconnect()));
	connect(ui->btnSendMsg,SIGNAL(clicked()),SLOT(onBtnSendMsg()));

	connect(_client,SIGNAL(incomming(QString)),SLOT(addData(QString)));
}

MainWindow::~MainWindow()
{
	delete ui;
}

void MainWindow::onBtnConnect(){
	_client->setConnection(ui->ipEdit->text(),ui->portEdit->text().toInt());
}

void MainWindow::onBtnDisconnect(){
	_client->disconnect();
}

void MainWindow::onBtnSendMsg(){
	_client->sendData(ui->userInput->toPlainText().toAscii());
	ui->userInput->clear();
}

void MainWindow::addData(QString data){
	ui->globalOutput->append(data + "\n");
}
